home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998…tember: Reference Library / Dev.CD Sep 98 RL2.toast / What's New / Software Development Kits / MacOS USB DDK / Examples / PrinterClassDriver / Utils.cp < prev    next >
Encoding:
Text File  |  1998-07-20  |  2.8 KB  |  127 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        Utils.cp
  3.  
  4.     Contains:    General utilities
  5.  
  6.     Copyright:    © 1998 by Apple Computer, Inc., all rights reserved.
  7.  
  8. */
  9. #include "Utils.h"
  10.  
  11.  
  12. /*-----------------------------------------------------------------------------*
  13.  
  14.     PStrEqualCaseInsensitive
  15.     
  16.     Desc:        Compares two Pascal strings while ignoring case
  17.  
  18.     In:            string1 - string to compare
  19.                 string2 - string to compare
  20.     Out:        none
  21.     
  22.     History:
  23.  
  24.     22 Mar 98    gp        Added.
  25.     
  26. *-----------------------------------------------------------------------------*/
  27. Boolean PStrEqualCaseInsensitive( Str255 string1, Str255 string2 )
  28. {
  29.     short    x;
  30.     char    c1, c2;
  31.     
  32.     if ( string1[0] != string2[0] )
  33.         return( false );
  34.         
  35.     for ( x=1; x<=string1[0]; x++ )
  36.     {
  37.         c1 = string1[x];
  38.         c2 = string2[x];
  39.         if ( c1 != c2 )
  40.         {
  41.             c1 &= ~32;
  42.             c2 &= ~32;
  43.             if ( (c1>='A') && (c1<='Z') && (c1 != c2) )
  44.                 return( false );
  45.         }
  46.     }
  47.     return( true );
  48. }
  49.  
  50. /*-----------------------------------------------------------------------------*
  51.  
  52.     AppendPStr
  53.     
  54.     Desc:        Copy a PASCAL style string to the source
  55.  
  56.     In:            mainStr - string to append to
  57.                 addStr - string to append
  58.     Out:        none
  59.     
  60.     History:
  61.  
  62.     22 Mar 98    gp        Added.
  63.     
  64. *-----------------------------------------------------------------------------*/
  65. void AppendPStr(StringPtr mainStr, StringPtr addStr)
  66.     {
  67.     register short    i;
  68.     register unsigned char    *pMainStr    = (unsigned char *)&mainStr[mainStr[0] + 1];
  69.     register unsigned char    *pAddStr    = (unsigned char *)&addStr[1];
  70.     register short    addLength    = (unsigned char)addStr[0];
  71.  
  72.     if (addLength)
  73.         {
  74.         // limit the ultimate length to 255 bytes
  75.         if ( ((unsigned char)mainStr[0] + addLength) > 255)
  76.             addLength    = 255 - (unsigned char)mainStr[0];
  77.  
  78.         // do the copy
  79.         for (i = 0; i < addLength; ++i)
  80.             *pMainStr++    = *pAddStr++;
  81.  
  82.         // update the count
  83.         mainStr[0]    += addLength;
  84.         }
  85.     }
  86.  
  87. /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  88.     
  89.     NameRegistryInstalled
  90.     
  91.     Desc:    Copies the contents of cell in the list hList into the string
  92.             pointed to by theString. The string is converted to a Pascal-
  93.             style string, with a preceding length byte.
  94.         
  95.         It is assumed that cell is a valid cell, that the cell contains no
  96.         more than 255 characters, and that theString and hList are not nil.
  97.  
  98.  
  99.     In:            Pointer to storage for a string.
  100.                 Coordinates of cell in list
  101.                 Handle to list
  102.  
  103.     Out:        String containing copy of cell text
  104.     
  105.     History:
  106.  
  107.             22 Mar 98    gp        Added.
  108. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
  109. void GetNameFromCell (StringPtr theString, Cell cell, ListHandle hList)
  110. {
  111.     short length;
  112.     
  113.     /*
  114.     The maximum length of the string is the size of a Str255, minus the
  115.     length byte…
  116.     */
  117.     length = sizeof(Str255) - 1;
  118.  
  119.     LGetCell((StringPtr)(theString + 1), &length, cell, hList);
  120.     
  121.     /*
  122.     Set the length byte.
  123.     */
  124.     *theString = (unsigned char) length;
  125. };
  126.  
  127.